1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Reference | open()


Syntax
open(path).read()

DescriptionThe open() command opens a file specified by the path parameter. The open() command can be used in two ways: open(path).read(), which returns the file's text content as a string, or, alternatively, open(path).readlines(), which returns a list of text lines.
Note:NodeBox looks for files relative to the current .py file. However, if you haven't saved your file first, NodeBox doesn't know where to look. Make sure you save the script first before you run it, otherwise NodeBox won't be able to find your file.
Returnsthe file's text content, as a string
Tutorial Strings


Example
# Prints the contents of sample.txt as a whole
txt = open("sample.txt").read()
print txt
 
# Prints the contents line per line
txt = open("sample.txt").readlines()
for line in txt:
    print line